home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5108 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.3 KB  |  71 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: 100435.736@compuserve.com (David A. Mair)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Interrupts in C++
  5. Date: Fri, 02 Feb 1996 15:22:52 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4eta8j$kb1@dub-news-svc-2.compuserve.com>
  8. References: <310FBF6A.6692@sask.aecl.ca>
  9. NNTP-Posting-Host: dd65-006.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Mark Kotyk <kotykm@sask.aecl.ca> wrote:
  13.  
  14. >I've been trying to get a good Com class going, but soon found 
  15. >out there is no easy way to get a Dos interrupt handler to sit 
  16. >in a class, and have access to private data members.  
  17.  
  18. >Any help.  I have picked up a package that did allow interrupts 
  19. >to be created dynamically, but it was rather large.
  20.  
  21. At first I thought you were off topic but considering the question of
  22. allowing a class to handle an asynchronously generated event that must
  23. be associated with a particular instance of a class is a reasonable
  24. C++ question, I suppose.
  25.  
  26. Here is how I would do what you want.  Make the interrupt handler a
  27. static member function and add a static member that is an array of
  28. pointers to the handler class.  For example:
  29.  
  30. class CComHandler
  31. {
  32.  
  33.     static CComHandler *Handlers[8];        // Handle up to 8 COM porst
  34.  
  35. public:
  36.     static void IntHandler();                // Interrupt handler
  37.  
  38.     void IntOnThisPort();
  39. };
  40.  
  41. Inthandler() can find the interrupt that was generated from the
  42. hardware in the computer.  This can be used to generate an integer
  43. quantity to be used as an index into the array.  The pointer at the
  44. index can be used to call the actual interrupt handler for the class,
  45. viz:
  46.  
  47. static void CComHandler::IntHandler()
  48. {
  49.     // Use the hardware to get the COM port as a number between 1 and 8
  50.     PortNum = (Some I/O operations);
  51.  
  52.     // Find the right handler
  53.     if (Handlers[PortNum] != NULL)
  54.     {
  55.         Handlers[PortNum]->IntOnThisPort();
  56.     }
  57.  
  58.     // Clear up the interrupt here or it will never be cleared
  59. }
  60.  
  61. This is by no means an exhaustive list of considerations, clearly the
  62. array will have to be initialised to NULLs in order to be sure that
  63. the conditional test in IntHandler() works.  Also, I have deliberately
  64. avoided the business of PC specific information as much as possible.
  65. Finally, I doubt my C++ is good enough for this to have no errors of
  66. style or compatibility with the draft standard.
  67.  
  68. Regards
  69. David.
  70.  
  71.